package com.tang.netty.aio.client;

import com.tang.netty.aio.ChannelAdapter;
import com.tang.netty.aio.ChannelHandler;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.charset.Charset;
import java.util.Date;

/**
 * 客户详细处理器
 * 
 * @author fulin.tang
 * @since 2021/8/7
 * @version 1.0
 */
@Slf4j
public class AioClientHandler extends ChannelAdapter {


    public AioClientHandler(AsynchronousSocketChannel channel, Charset charset) {
        super(channel, charset);
    }

    @Override
    public void channelActive(ChannelHandler ctx) {
        try{
            log.info("连接报告信息：{}", ctx.channel().getRemoteAddress());
            // 通知客户端建立连接成功
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void channelInactive(ChannelHandler ctx) {

    }

    @Override
    public void channelRead(ChannelHandler ctx, Object msg) {
        log.info("服务端收到：{} {}\r\n", new Date(), msg);
        ctx.writeAndFlush("客户端处理信息Success！\r\n");
    }
    
}
